/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.unwiredgrain.modeling.sscm.impl;

import com.unwiredgrain.modeling.sscm.SSCMPackage;

import com.unwiredgrain.modeling.sscm.TypeModifier;
import com.unwiredgrain.modeling.sscm.TypeTemplateInstantiation;
import com.unwiredgrain.modeling.sscm.TypeTemplateArgument;
import com.unwiredgrain.modeling.sscm.TypedElement;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;


/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Typed Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.TypedElementImpl#getTypeTemplateInstantiation <em>Type Template Instantiation</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.TypedElementImpl#getType <em>Type</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.TypedElementImpl#getModifier <em>Modifier</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.TypedElementImpl#getCppName <em>Cpp Name</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.TypedElementImpl#getTypeName <em>Type Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class TypedElementImpl extends NamedElementImpl implements TypedElement {
	/**
	 * The cached value of the '{@link #getTypeTemplateInstantiation() <em>Type Template Instantiation</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeTemplateInstantiation()
	 * @generated
	 * @ordered
	 */
	protected TypeTemplateInstantiation typeTemplateInstantiation;

	/**
	 * The default value of the '{@link #getModifier() <em>Modifier</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModifier()
	 * @generated
	 * @ordered
	 */
	protected static final TypeModifier MODIFIER_EDEFAULT = TypeModifier.NO_MODIFIER;

	/**
	 * The cached value of the '{@link #getModifier() <em>Modifier</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModifier()
	 * @generated
	 * @ordered
	 */
	protected TypeModifier modifier = MODIFIER_EDEFAULT;

	/**
	 * The default value of the '{@link #getCppName() <em>Cpp Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCppName()
	 * @generated
	 * @ordered
	 */
	protected static final String CPP_NAME_EDEFAULT = null;

	/**
	 * The default value of the '{@link #getTypeName() <em>Type Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeName()
	 * @generated
	 * @ordered
	 */
	protected static final String TYPE_NAME_EDEFAULT = null;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TypedElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SSCMPackage.Literals.TYPED_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TypeTemplateInstantiation getTypeTemplateInstantiation() {
		return typeTemplateInstantiation;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTypeTemplateInstantiation(TypeTemplateInstantiation newTypeTemplateInstantiation, NotificationChain msgs) {
		TypeTemplateInstantiation oldTypeTemplateInstantiation = typeTemplateInstantiation;
		typeTemplateInstantiation = newTypeTemplateInstantiation;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION, oldTypeTemplateInstantiation, newTypeTemplateInstantiation);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypeTemplateInstantiation(TypeTemplateInstantiation newTypeTemplateInstantiation) {
		if (newTypeTemplateInstantiation != typeTemplateInstantiation) {
			NotificationChain msgs = null;
			if (typeTemplateInstantiation != null)
				msgs = ((InternalEObject)typeTemplateInstantiation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION, null, msgs);
			if (newTypeTemplateInstantiation != null)
				msgs = ((InternalEObject)newTypeTemplateInstantiation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION, null, msgs);
			msgs = basicSetTypeTemplateInstantiation(newTypeTemplateInstantiation, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION, newTypeTemplateInstantiation, newTypeTemplateInstantiation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TypeModifier getModifier() {
		return modifier;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setModifier(TypeModifier newModifier) {
		TypeModifier oldModifier = modifier;
		modifier = newModifier == null ? MODIFIER_EDEFAULT : newModifier;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.TYPED_ELEMENT__MODIFIER, oldModifier, modifier));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TypeTemplateArgument getType() {
		TypeTemplateArgument type = basicGetType();
		return type != null && type.eIsProxy() ? (TypeTemplateArgument)eResolveProxy((InternalEObject)type) : type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public TypeTemplateArgument basicGetType() {
		// DONE: implement this method to return the 'Type' reference
		// -> do not perform proxy resolution
		// Ensure that you remove @generated or mark it @generated NOT
		// throw new UnsupportedOperationException();
		if (getTypeTemplateInstantiation() == null) {
			return null;
		}
		
		return getTypeTemplateInstantiation().getTypeArgument();
	}

	/**
	 * <!-- begin-user-doc -->
	 * setType is a non-transient, volatile method. So modifying object structure won't interfere with default object serialization/deserialization.
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setType(TypeTemplateArgument newType) {
		// DONE: implement this method to set the 'Type' reference
		// Ensure that you remove @generated or mark it @generated NOT
		// throw new UnsupportedOperationException();
		
		// clear TypeTemplateArgument
		TypeTemplateArgument oldType = getType();
		
		if (oldType == null && newType == null) {
			return;
		}
		
		if (newType == null) {
			
			setTypeTemplateInstantiation(null);
			
			if (eNotificationRequired()) {
				eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.TYPED_ELEMENT__TYPE, oldType, newType));
			}
			
			return;
		}
		
		if (getTypeTemplateInstantiation() == null) {
			TypeTemplateInstantiation tti = SSCMFactoryImpl.eINSTANCE.createTypeTemplateInstantiation();
			setTypeTemplateInstantiation(tti);
		}
		
		getTypeTemplateInstantiation().setTypeArgument(newType);
		
		if (eNotificationRequired()) {
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.TYPED_ELEMENT__TYPE, oldType, newType));
		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getCppName() {
		// DONE: implement this method to return the 'Cpp Name' attribute
		// Ensure that you remove @generated or mark it @generated NOT
		// throw new UnsupportedOperationException();
		return "[Derived class should override getCppName in TypedElement.]";
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public String getTypeName() {
		// DONE: implement this method to return the 'Type Name' attribute
		// Ensure that you remove @generated or mark it @generated NOT
		// throw new UnsupportedOperationException();
		if (getTypeTemplateInstantiation() == null) {
			return null;
		}
		
		return getTypeTemplateInstantiation().getCppName();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION:
				return basicSetTypeTemplateInstantiation(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION:
				return getTypeTemplateInstantiation();
			case SSCMPackage.TYPED_ELEMENT__TYPE:
				if (resolve) return getType();
				return basicGetType();
			case SSCMPackage.TYPED_ELEMENT__MODIFIER:
				return getModifier();
			case SSCMPackage.TYPED_ELEMENT__CPP_NAME:
				return getCppName();
			case SSCMPackage.TYPED_ELEMENT__TYPE_NAME:
				return getTypeName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION:
				setTypeTemplateInstantiation((TypeTemplateInstantiation)newValue);
				return;
			case SSCMPackage.TYPED_ELEMENT__TYPE:
				setType((TypeTemplateArgument)newValue);
				return;
			case SSCMPackage.TYPED_ELEMENT__MODIFIER:
				setModifier((TypeModifier)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION:
				setTypeTemplateInstantiation((TypeTemplateInstantiation)null);
				return;
			case SSCMPackage.TYPED_ELEMENT__TYPE:
				setType((TypeTemplateArgument)null);
				return;
			case SSCMPackage.TYPED_ELEMENT__MODIFIER:
				setModifier(MODIFIER_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SSCMPackage.TYPED_ELEMENT__TYPE_TEMPLATE_INSTANTIATION:
				return typeTemplateInstantiation != null;
			case SSCMPackage.TYPED_ELEMENT__TYPE:
				return basicGetType() != null;
			case SSCMPackage.TYPED_ELEMENT__MODIFIER:
				return modifier != MODIFIER_EDEFAULT;
			case SSCMPackage.TYPED_ELEMENT__CPP_NAME:
				return CPP_NAME_EDEFAULT == null ? getCppName() != null : !CPP_NAME_EDEFAULT.equals(getCppName());
			case SSCMPackage.TYPED_ELEMENT__TYPE_NAME:
				return TYPE_NAME_EDEFAULT == null ? getTypeName() != null : !TYPE_NAME_EDEFAULT.equals(getTypeName());
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (modifier: ");
		result.append(modifier);
		result.append(')');
		return result.toString();
	}

} //TypedElementImpl
